= form_for [organization, @server, @credential], :remote => true do |f|
  = f.error_messages
  %fieldset.fieldSet
    .fieldSet__field
      = f.label :type, :class => 'fieldSet__label'
      .fieldSet__input
        = f.select :type, Credential::TYPES, {}, :disabled => @credential.persisted?, :class => 'input input--select', :autofocus => @credential.new_record?
        %p.fieldSet__text
          This is the service that is associated with this credential. You'll be able to use this key to
          authenticate to this type of service only.
    .fieldSet__field
      = f.label :name, :class => 'fieldSet__label'
      .fieldSet__input
        = f.text_field :name, :autofocus => @credential.persisted?, :class => 'input input--text'
        %p.fieldSet__text
          This is a friendly name so you can identify this credential later. You can enter anything
          you want here, the more descriptive the better.

    .fieldSet__field{data: {credential_key_type: 'all'}}
      = f.label :key, :class => 'fieldSet__label'
      .fieldSet__input
        = f.text_field :key, :readonly => false, :class => 'input input--text input--code', :placeholder => "Automatically generated", :tabindex => 1000, :value => (@credential.new_record? ? '' : @credential.key)
        %p.fieldSet__text
          This is the unique key which will be used to authenticate any requests to the API or the SMTP servers.
          It will be generated randomly and cannot be changed. If you need a new token, you can create a new one and then
          delete the old one when you're ready.

    .fieldSet__field{data: {credential_key_type: 'smtp-ip'}}
      = f.label :key, "Network", :class => 'fieldSet__label'
      .fieldSet__input
        = f.text_field :key, :class => 'input input--text input--code'
        %p.fieldSet__text
          This is the IP address or network that you wish to allow to authenticate to this mail server.

    .fieldSet__field
      = f.label :hold, :class => 'fieldSet__label'
      .fieldSet__input
        = f.select :hold, [["Process all messages", false], ["Hold messages from this credential", true]], {}, :class => 'input input--select'
        %p.fieldSet__text
          You may wish to automatically hold all messages that are sent by this credential. This allows you to preview them
          before they are delivered to their recipients. This is useful for credentials for development environments.

  .fieldSetSubmit.buttonSet
    = f.submit @credential.new_record? ? "Create credential" : "Save credential", :class => 'button button--positive js-form-submit'
    .fieldSetSubmit__delete
      - if f.object.persisted?
        = link_to "Delete credential", [organization, @server, @credential], :remote => true, :class => 'button button--danger', :method => :delete, :data => {:confirm => "Are you sure you wish to delete this credential?"}

